<?php

require_once 'common/conn.php';
if (isset($_GET['type'])) {
    $type = trim($_GET['type']);
}
if (isset($_GET['ability'])) {
    $ability = trim($_GET['ability']);
}
if (isset($_GET['age'])) {
    $age = trim($_GET['age']);
}
if (isset($_GET['name'])) {
    $name = trim($_GET['name']);
}

if (isset($_GET['start'])) {
    $start = $_GET['start'];
} else {
    $start = 0;
}
if (isset($_GET['limit'])) {
    $limit = $_GET['limit'];
}

$sql = "SELECT productid,flashcode,age,name,url,imageURL,version,size,type1,type2,type3,downloadtimes FROM t_product WHERE status = 1";
if (isset($type) && $type != "") {
    $sql = $sql . " AND type1 = " . $type;
}
if (isset($ability) && $ability != "") {
    $sql = $sql . " AND type2 LIKE '%" . $ability . "%'";
}
if (isset($age) && $age != "") {
    $sql = $sql . " AND age = " . $age;
}

if (mb_check_encoding($name, "utf-8") == false) {
    if (mb_check_encoding($name, "gbk") == true) {
        $name = mb_convert_encoding($name, "utf-8", "gbk");
    } else {
        $name = mb_convert_encoding($name, "utf-8");
    }
}
if (isset($name) && $name != "") {
    $sql = $sql . " AND name LIKE '%" . $name . "%'";
}
if (isset($start) && isset($limit)) {
    $sql = $sql . " ORDER BY flashcode LIMIT " . $start . "," . $limit;
}
$db = new DBC();
$data = $db->fetchData($sql);
echo json_encode($data);
?>
